﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:COL_OUTSEE
	/// </summary>
	public partial class COL_OUTSEE : BaseDAL<GSLMS.Entity.TB_COL_OUTSEE>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public COL_OUTSEE()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_COL_OUTSEE model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_EMPNAME", model.EMPNAME),
								new OracleParameter("P_EMPID", model.EMPID),
								new OracleParameter("P_APPLYDATE", model.APPLYDATE),
								new OracleParameter("P_OUTDATE", model.OUTDATE),
								new OracleParameter("P_OUTHOUR", model.OUTHOUR),
								new OracleParameter("P_OUTSECOND", model.OUTSECOND),
								new OracleParameter("P_INTRADAYBACK", model.INTRADAYBACK),
								new OracleParameter("P_APPLYID", model.APPLYID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CHANID", model.CHANID),
								new OracleParameter("P_CHANNAME", model.CHANNAME),
								new OracleParameter("P_OUTTYPE", model.OUTTYPE),
								new OracleParameter("P_DETAIL", model.DETAIL),
								new OracleParameter("P_BACKDATE", model.BACKDATE),
								new OracleParameter("P_SIGNMAN", model.SIGNMAN),
								new OracleParameter("P_ISBACK", model.ISBACK),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_AUDITBY", model.AUDITBY),
								new OracleParameter("P_AUDITDATE", model.AUDITDATE),
								new OracleParameter("P_AUDITCONTENT", model.AUDITCONTENT),
								new OracleParameter("P_AUDITRESULT", model.AUDITRESULT),
								new OracleParameter("P_SIGNSTATUS", model.SIGNSTATUS)};
  
			for (int i = 0; i < 23; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_outsee_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_COL_OUTSEE model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_EMPNAME", model.EMPNAME),
								new OracleParameter("P_EMPID", model.EMPID),
								new OracleParameter("P_APPLYDATE", model.APPLYDATE),
								new OracleParameter("P_OUTDATE", model.OUTDATE),
								new OracleParameter("P_OUTHOUR", model.OUTHOUR),
								new OracleParameter("P_OUTSECOND", model.OUTSECOND),
								new OracleParameter("P_INTRADAYBACK", model.INTRADAYBACK),
								new OracleParameter("P_APPLYID", model.APPLYID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CHANID", model.CHANID),
								new OracleParameter("P_CHANNAME", model.CHANNAME),
								new OracleParameter("P_OUTTYPE", model.OUTTYPE),
								new OracleParameter("P_DETAIL", model.DETAIL),
								new OracleParameter("P_BACKDATE", model.BACKDATE),
								new OracleParameter("P_SIGNMAN", model.SIGNMAN),
								new OracleParameter("P_ISBACK", model.ISBACK),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_AUDITBY", model.AUDITBY),
								new OracleParameter("P_AUDITDATE", model.AUDITDATE),
								new OracleParameter("P_AUDITCONTENT", model.AUDITCONTENT),
								new OracleParameter("P_AUDITRESULT", model.AUDITRESULT),
								new OracleParameter("P_SIGNSTATUS", model.SIGNSTATUS)};
  
			for (int i = 0; i < 23; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_outsee_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_outsee_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_COL_OUTSEE DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_COL_OUTSEE model = new GSLMS.Entity.TB_COL_OUTSEE();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["EMPNAME"]!=null && dr["EMPNAME"].ToString()!="")
				{
					model.EMPNAME=dr["EMPNAME"].ToString();
				}
				if(dr["EMPID"]!=null && dr["EMPID"].ToString()!="")
				{
					model.EMPID=OracleHelper.ToLong(dr["EMPID"].ToString());
				}
				if(dr["APPLYDATE"]!=null && dr["APPLYDATE"].ToString()!="")
				{
					model.APPLYDATE=DateTime.Parse(dr["APPLYDATE"].ToString());
				}
				if(dr["OUTDATE"]!=null && dr["OUTDATE"].ToString()!="")
				{
					model.OUTDATE=DateTime.Parse(dr["OUTDATE"].ToString());
				}
				if(dr["OUTHOUR"]!=null && dr["OUTHOUR"].ToString()!="")
				{
                    model.OUTHOUR = OracleHelper.ToInt(dr["OUTHOUR"].ToString());
				}
				if(dr["OUTSECOND"]!=null && dr["OUTSECOND"].ToString()!="")
				{
                    model.OUTSECOND = OracleHelper.ToInt(dr["OUTSECOND"].ToString());
				}
				if(dr["INTRADAYBACK"]!=null && dr["INTRADAYBACK"].ToString()!="")
				{
                    model.INTRADAYBACK = OracleHelper.ToInt(dr["INTRADAYBACK"].ToString());
				}
				if(dr["APPLYID"]!=null && dr["APPLYID"].ToString()!="")
				{
					model.APPLYID=OracleHelper.ToLong(dr["APPLYID"].ToString());
				}
				if(dr["CUSTNAME"]!=null && dr["CUSTNAME"].ToString()!="")
				{
					model.CUSTNAME=dr["CUSTNAME"].ToString();
				}
				if(dr["CHANID"]!=null && dr["CHANID"].ToString()!="")
				{
					model.CHANID=OracleHelper.ToLong(dr["CHANID"].ToString());
				}
				if(dr["CHANNAME"]!=null && dr["CHANNAME"].ToString()!="")
				{
					model.CHANNAME=dr["CHANNAME"].ToString();
				}
				if(dr["OUTTYPE"]!=null && dr["OUTTYPE"].ToString()!="")
				{
					model.OUTTYPE=dr["OUTTYPE"].ToString();
				}
				if(dr["DETAIL"]!=null && dr["DETAIL"].ToString()!="")
				{
					model.DETAIL=dr["DETAIL"].ToString();
				}
				if(dr["BACKDATE"]!=null && dr["BACKDATE"].ToString()!="")
				{
					model.BACKDATE=DateTime.Parse(dr["BACKDATE"].ToString());
				}
				if(dr["SIGNMAN"]!=null && dr["SIGNMAN"].ToString()!="")
				{
					model.SIGNMAN=dr["SIGNMAN"].ToString();
				}
				if(dr["ISBACK"]!=null && dr["ISBACK"].ToString()!="")
				{
                    model.ISBACK = OracleHelper.ToInt(dr["ISBACK"].ToString());
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["AUDITBY"]!=null && dr["AUDITBY"].ToString()!="")
				{
					model.AUDITBY=dr["AUDITBY"].ToString();
				}
				if(dr["AUDITDATE"]!=null && dr["AUDITDATE"].ToString()!="")
				{
					model.AUDITDATE=DateTime.Parse(dr["AUDITDATE"].ToString());
				}
				if(dr["AUDITCONTENT"]!=null && dr["AUDITCONTENT"].ToString()!="")
				{
					model.AUDITCONTENT=dr["AUDITCONTENT"].ToString();
				}
				if(dr["AUDITRESULT"]!=null && dr["AUDITRESULT"].ToString()!="")
				{
                    model.AUDITRESULT = OracleHelper.ToInt(dr["AUDITRESULT"].ToString());
				}
				if(dr["SIGNSTATUS"]!=null && dr["SIGNSTATUS"].ToString()!="")
				{
                    model.SIGNSTATUS = OracleHelper.ToInt(dr["SIGNSTATUS"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_COL_OUTSEE GetByID(long ID)
		{
			GSLMS.Entity.TB_COL_OUTSEE sModel = new GSLMS.Entity.TB_COL_OUTSEE();
			string sql = "";
			sql = "select * from TB_COL_OUTSEE where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_COL_OUTSEE> GetList(GSLMS.Entity.TB_COL_OUTSEE searchParam)
		{
			var list=new List<GSLMS.Entity.TB_COL_OUTSEE>();
			DataTable dt = null;
			string tblName = "TB_COL_OUTSEE";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_COL_OUTSEE model = new GSLMS.Entity.TB_COL_OUTSEE();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

